package bishi.wangyi;

import java.util.Scanner;

public class demo2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        int k = in.nextInt();
        int left= 0;
        int right = 0;
        int[] hash = new int[128];
        int max = 0;
        while(right < s.length()) {
            if(s.charAt(right) >= '0' && s.charAt(right) <= '9') {
                right++;
            }else {
                char temp = s.charAt(right);
                int index = temp -'A';
                hash[index]++;
                if(hash[index]  > k) {
                    int len = right - left ;
                    if(max < len) {
                        max = len;
                    }

                    while(hash[index] > k) {
                        if(s.charAt(left) >= '0' && s.charAt(left) <= '9') {
                            left++;
                        }else {
                            char x = s.charAt(left);
                            int cur = x - 'A';
                            hash[cur]--;
                            left++;
                        }
                    }
                }
                right++;
            }
        }
        System.out.println(max);
    }
}
